package com.ruoyi.inform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inform.domain.Inform;
import com.ruoyi.inform.service.IInformService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告发布与编辑Controller
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/inform/manage")
public class InformController extends BaseController
{
    @Autowired
    private IInformService informService;

    /**
     * 查询公告发布与编辑列表
     */
//    @PreAuthorize("@ss.hasPermi('inform:manage:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Inform inform)
    {
        startPage();
        List<Inform> list = informService.selectInformList(inform);
        return getDataTable(list);
    }


    /**
     * 查询公告发布与编辑列表return List
     */
//    @PreAuthorize("@ss.hasPermi('inform:manage:list')")
    @Anonymous
    @GetMapping("/getList")
    public List getList(Inform inform)
    {
        return informService.selectInformList(inform);
    }





    /**
     * 导出公告发布与编辑列表
     */
    @PreAuthorize("@ss.hasPermi('inform:manage:export')")
    @Log(title = "公告发布与编辑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Inform inform)
    {
        List<Inform> list = informService.selectInformList(inform);
        ExcelUtil<Inform> util = new ExcelUtil<Inform>(Inform.class);
        util.exportExcel(response, list, "公告发布与编辑数据");
    }

    /**
     * 获取公告发布与编辑详细信息
     */
    @PreAuthorize("@ss.hasPermi('inform:manage:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Long newsId)
    {
        return success(informService.selectInformByNewsId(newsId));
    }

    /**
     * 新增公告发布与编辑
     */
    @PreAuthorize("@ss.hasPermi('inform:manage:add')")
    @Log(title = "公告发布与编辑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Inform inform)
    {
        return toAjax(informService.insertInform(inform));
    }

    /**
     * 修改公告发布与编辑
     */
    @PreAuthorize("@ss.hasPermi('inform:manage:edit')")
    @Log(title = "公告发布与编辑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Inform inform)
    {
        return toAjax(informService.updateInform(inform));
    }

    /**
     * 删除公告发布与编辑
     */
    @PreAuthorize("@ss.hasPermi('inform:manage:remove')")
    @Log(title = "公告发布与编辑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public AjaxResult remove(@PathVariable Long[] newsIds)
    {
        return toAjax(informService.deleteInformByNewsIds(newsIds));
    }
}
